package com.example.composemodifiterdemo

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.Card
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp

/**
 *@author: njb
 *@date:  2023/2/8 19:06
 *@desc:
 */
class ListColumnSampleActivity:ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
          lazy()
        }
    }

    @Preview
    @Composable
    fun lazy(){
        LazyColumn(
            modifier = Modifier
                .fillMaxSize()
                .background(Color.Gray),
            contentPadding = PaddingValues(35.dp),
            verticalArrangement = Arrangement.spacedBy(10.dp)//设置item之间的间距
        ){
            items(50) { index ->
              ContentCardSample(index = index)
            }
        }
    }

    @Composable
    fun ContentCardSample(index: Int){
        Card(
            elevation = 8.dp,
            modifier = Modifier.fillMaxWidth()
        ){
            Box(
                modifier = Modifier
                    .fillMaxSize()
                    .padding(15.dp),
                contentAlignment = Alignment . Center
            ){
                Text(text = "我是序号第 $index 位的卡片",
                style = MaterialTheme.typography.h5)
            }
        }
    }
}